﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GetAllCityCode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            省市县数据抓取 getall = new 省市县数据抓取();
            this.dataGridView1.DataSource = getall.SaveList;
            // getall.Save();



        }

        private void button2_Click(object sender, EventArgs e)
        {
            CityDataSetTableAdapters.base_cityTableAdapter cityTap = new CityDataSetTableAdapters.base_cityTableAdapter();
            // cityTap.Update();

            CityDataSet.base_cityDataTable ctb = new CityDataSet.base_cityDataTable();
            //MessageBox.Show(Convert.ToString(this.dataGridView1.Rows[0].Cells[4].Value));
            for (int i = 0; i < this.dataGridView1.RowCount; i++)
            {

                ctb.Addbase_cityRow(
                    //Convert.ToString(this.dataGridView1.Rows[i].Cells[1].Value),
                    //Convert.ToString(this.dataGridView1.Rows[i].Cells[2].Value),
                    //Convert.ToString(this.dataGridView1.Rows[i].Cells[3].Value),
                    //Convert.ToString(this.dataGridView1.Rows[i].Cells[4].Value),
                    //Int32.Parse(this.dataGridView1.Rows[i].Cells[5].Value.ToString()),
                    //Convert.ToString(this.dataGridView1.Rows[i].Cells[6].Value)

                 //convert.tostring(),太吃内存。改进如下：
                this.dataGridView1.Rows[i].Cells[1].Value.ToString(),
                this.dataGridView1.Rows[i].Cells[2].Value.ToString(),
                this.dataGridView1.Rows[i].Cells[3].Value.ToString(),
                Convert.ToString(this.dataGridView1.Rows[i].Cells[4].Value),
                Int32.Parse(this.dataGridView1.Rows[i].Cells[5].Value.ToString()),
                this.dataGridView1.Rows[i].Cells[6].Value.ToString()

               );

            }
            cityTap.Update(ctb);

            MessageBox.Show("存到数据库成功！");

            //convert.tostring(),太吃内存。
        }
    }
}
